const primaryTable = [
  1, 101, 503, 1009, 3001, 5003, 7459, 8629,
  10007, 15101, 19843, 20929, 23071, 25073, 27073, 29231,
  31019, 35023, 37337, 38119, 41113, 43933, 46337, 48523,
  51859, 53201, 55333, 58511, 60811, 63857, 65851, 68743,
  71983, 73583, 76261, 80207, 85889, 87251, 91801, 97003
]

export function csrfEncode(ipHash: number): string {
  const timestamp = Date.now() % 3600000
  const primaryIndex = Math.round(Math.random() * 31)
  const primary = primaryTable[primaryIndex]
  const x1 = timestamp
  const x2 = x1 * primary
  const x3 = x2 + ipHash
  const x4 = (x3 * 32) + primaryIndex
  const x5 = Number(x4).toString(16)
  return x5
}
